// /common/http.api.js

// 如果没有通过拦截器配置域名的话，可以在这里写上完整的URL(加上域名部分)
// let hotSearchUrl = '/ebapi/store_api/hot_search';
// let indexUrl = '/ebapi/public_api/index';

// 此处第二个参数vm，就是我们在页面使用的this，你可以通过vm获取vuex等操作，更多内容详见uView对拦截器的介绍部分：
// https://uviewui.com/js/http.html#%E4%BD%95%E8%B0%93%E8%AF%B7%E6%B1%82%E6%8B%A6%E6%88%AA%EF%BC%9F
const install = (Vue, vm) => {
	// 此处没有使用传入的params参数
	// let getSearch = (params = {}) => vm.$u.get(hotSearchUrl, {
	// 	id: 2
	// });

	// 此处使用了传入的params参数，一切自定义即可
	// let getInfo = (params = {}) => vm.$u.post(indexUrl, params);

	// 将各个定义的接口名称，统一放进对象挂载到vm.$u.api(因为vm就是this，也即this.$u.api)下
	let getUser = (
		params = {}) => vm.$u.get('/user', params)


	// 注册
	let register = (
		params = {}) => vm.$u.post('/account/?action=register', params)
	// 登录
	let login = (
		params = {}) => vm.$u.post('/account/?action=login', params)
	// 找回密码
	let changePwd = (
		params = {}) => vm.$u.post("/account/?action=change_password&token=" + vm.vuex_token, params)
	// 退出登录
	let logout = (
		params = {}) => vm.$u.post("/account/?action=logout", params)
	//初始化车位
	let initialPark = (
		params = {}) => vm.$u.get("/booking/?action=initial", params)
	// 查询某个时间段的车位
	let inquireBooking = (
		params = {}) => vm.$u.post("/booking/?action=inquire_booking&token=" + vm.vuex_token, params)
	// 获取车辆列表
	let getCarList = (
		params = {}) => vm.$u.post("/query/?action=query_car&token=" + vm.vuex_token, params)
	// 添加车辆
	let addCar = (
		params = {}) => vm.$u.post("/service/?action=add_car&token=" + vm.vuex_token, params)
	// 删除车辆
	let deleteCar = (
		params = {}) => vm.$u.post("/service/?action=delete_car&token=" + vm.vuex_token, params)
	// 获取专属车位列表
	let getStallVip = (
		params = {}) => vm.$u.post("/query/?action=query_park&token=" + vm.vuex_token, params)
	// 申请专属车位
	let addStallVip = (
		params = {}) => vm.$u.post("/service/?action=apply_parking&token=" + vm.vuex_token, params)
	// 开始预约
	let startBooking = (
		params = {}) => vm.$u.post("/booking/?action=start_booking&token=" + vm.vuex_token, params)
	// 获取预约记录
	let getBookingHistory = (
		params = {}) => vm.$u.post("/query/?action=query_booking&token=" + vm.vuex_token, params)
	// 取消预约
	let cancelBooking = (
		params = {}) => vm.$u.post("/booking/?action=cancel_booking&token=" + vm.vuex_token, params)
	// 获取使用记录
	let getUsageHistory = (
		params = {}) => vm.$u.post("/query/?action=query_usage&token=" + vm.vuex_token, params)
	vm.$u.api = {
		register,
		login,
		changePwd,
		logout,
		initialPark,
		inquireBooking,
		getCarList,
		addCar,
		deleteCar,
		getUser,
		getStallVip,
		addStallVip,
		startBooking,
		getBookingHistory,
		cancelBooking,
		getUsageHistory,
		// };
	}
}
export default {
	install
}
